package com.wk.pms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wk.common.bean.PageVo;
import com.wk.common.bean.Query;
import com.wk.common.bean.QueryCondition;
import com.wk.common.bean.Resp;
import com.wk.pms.entity.Brand;
import com.wk.pms.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    @GetMapping("list")
    public Resp<PageVo> list(QueryCondition condition){
        IPage<Brand> page = brandService.page(new Query<Brand>().getPage(condition));
        return Resp.ok(new PageVo(page));
    }

    /**
     * 信息
     */
    @GetMapping("/info/{brandId}")
    public Resp<Brand> info(@PathVariable("brandId") Long brandId){
        Brand brand = brandService.getById(brandId);

        return Resp.ok(brand);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public Resp<Object> save(@RequestBody Brand brand){
        brandService.save(brand);

        return Resp.ok(null);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public Resp<Object> update(@RequestBody Brand brand){
        brandService.updateById(brand);
        return Resp.ok(null);
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public Resp<Object> delete(@RequestBody Long[] brandIds){
        brandService.removeByIds(Arrays.asList(brandIds));
        return Resp.ok(null);
    }

    
}

